// import cors from '@koa/cors';
import Koa from 'koa';
// import KoaBodyParser from 'koa-bodyparser';
// import mount from 'koa-mount';
// import serve from 'koa-static';
// import { config, json, jwt, Loader, logging, success } from 'lin-mizar';
// import WebSocket from './extension/socket/socket';

/**
 * 首页
 */
function indexPage(app) {
  // app.context.loader.mainRouter.get('/', async ctx => {
  //   ctx.type = 'html';
  //   ctx.body = `<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor:
  //     pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family:
  //     "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal;
  //     margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"><p>
  //     Lin <br/><span style="font-size:30px">心上无垢，林间有风。</span></p></div> `;
  // });

  app.use(async ctx => {
    ctx.body = `<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor:
      pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family:
      "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal;
      margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"><p>
      Lin <br/><span style="font-size:30px">心上无垢，林间有风。</span></p></div> `;
  });
}

/**
 * 初始化Koa实例
 */
async function createApp() {
  const app = new Koa();
  // applyBodyParse(app);
  // applyCors(app);
  // applyStatic(app);
  // const { log, error, Lin, multipart } = require('lin-mizar');
  // app.use(log);
  // app.on('error', error);
  // applyDefaultExtends(app);
  // applyLoader(app);
  // applyJwt(app);
  // const lin = new Lin();
  // await lin.initApp(app, true); // 是否挂载插件路由，默认为true
  // await PermissionModel.initPermission();
  indexPage(app);
  // multipart(app);
  // return applyWebSocket(app);
  return app;
}

module.exports = { createApp };
